﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class CourseDAO : CommonDAO
    {
        private string sql_cancelCourse = "delete from Student_Course where StudentId = @StudentId and CourseId = @CourseId";
        private string sql_selectCourse = "insert into Student_Course(StudentId, CourseID) values(@StudentId, @CourseId)";
        private string sql_deleteCourse = "delete from Course where CourseID = @CourseID";
        public bool cancelCourse(string studentId, string courseId)
        {
            SqlCommand cmd = this.getCommand(sql_cancelCourse);
            cmd.Parameters.Add("@StudentId", SqlDbType.VarChar, 10).Value = studentId;
            cmd.Parameters.Add("@CourseId", SqlDbType.VarChar, 10).Value = courseId;
            int ret = this.ExecuteNonQueryCommand(cmd);
            return ret == 1;
        }

        public bool selectCourse(String studentId, string courseId)
        {
            SqlCommand cmd = this.getCommand(sql_selectCourse);
            cmd.Parameters.Add("@StudentId", SqlDbType.VarChar, 10).Value = studentId;
            cmd.Parameters.Add("@CourseId", SqlDbType.VarChar, 10).Value = courseId;
            int ret = this.ExecuteNonQueryCommand(cmd);
            return ret == 1;
        }

        public bool deleteByID(string courseId)
        {
            SqlCommand cmd = this.getCommand(sql_deleteCourse);
            cmd.Parameters.Add("@CourseID", SqlDbType.VarChar, 10).Value = courseId;
            int ret = this.ExecuteNonQueryCommand(cmd);
            return ret == 1;
        }
    }
}
